/*------------------------------------------------------*/
/*                                                      */
/* Copyright (C)	sky-mobi.com                        */
/* All rights reserved                                  */
/*                                                      */
/* Author   tristan.yang                                */
/*                                                      */
/* History  2012-06-26 created                          */
/*                                                      */
/*------------------------------------------------------*/

#ifndef __POINT_BASE_H__
#define __POINT_BASE_H__

#include "RtTimerWrapper.h"
#include "vcsbase.h"

class CPointBase;
class CPointSink
{
public:
	virtual RtResult OnDisconnect(RtResult aReason, CPointBase* pPB) = 0;
	virtual RtResult OnNewPointLogin(CPointBase* pPB) = 0;
	virtual RtResult OnText(CPointBase* pPB, int nDstID, int nPrivate, const CRtString& strMessage) = 0;

	virtual ~CPointSink() {}
};

class RT_API_EXPORT CPointBase : 
public CRtReferenceControlSingleThread
, public CRtTimerWrapperSink
{
public:
	enum{
		ST_None = 0,
		ST_Logined = 1,
		ST_DisConn = 2,
	};
	CPointBase(CPointSink* pSink, DWORD inType);
	virtual ~CPointBase();
	
	virtual TransportAddress GetPeerAddr() = 0;
	
	virtual void SetStatus(DWORD st){m_dwStatus = st;}
	virtual void DisconnectSelf() = 0;

	virtual INT GetNodeId(){return m_defaultUser.m_iNodeid;}
	virtual SKYID GetUsrId(){return m_defaultUser.m_iUsrid;}
	virtual DWORD GetLastTick(){return m_dwLiveTick;}

	virtual s_UserInfo& GetUserInfo(WORD rmid = DEFAULT_NODEID);
	virtual void SetUserInfo(WORD rmid, const s_UserInfo& info);

	virtual WORD GetRoomID();
	
protected: // from CRtTimerWrapperSink
	virtual void OnTimer(CRtTimerWrapper* aID);

protected:
	typedef std::list<CRtMessageBlock*> MESSAGE_LIST;
	typedef MESSAGE_LIST::iterator MESSAGE_ITOR;

	virtual RtResult SendData(CRtMessageBlock &aData) = 0;

	RtResult SendMsg(CRtMessageBlock& msg);	
	void	SendCacheData();
	BOOL	bLogin(){return ST_Logined == m_dwStatus;}

private:

protected:
	// diff permission and usr type in diff room
	UserInfoMapType	m_userInfoMap;
	s_UserInfo		m_defaultUser;
	WORD			m_nRoomID;

	DWORD			m_dwLiveTick;
	CPointSink*		m_pPointSink;
	MESSAGE_LIST	m_CacheMsgList;
	BOOL			m_bCanSend;

	DWORD			m_dwStatus;
	DWORD			m_dwUsrDownCount;
};

#endif//__POINT_BASE_H__
